home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 173 / 173.xpi / chrome / gm-notifier.jar / content / gm-notifier / console.xul < prev    next >
Extensible Markup Language  |  2009-09-28  |  7KB  |  177 lines

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
  3. <?xml-stylesheet href="chrome://gm-notifier/content/gm-notifier-dialogs.css" type="text/css"?>
  4.  
  5. <!DOCTYPE dialog SYSTEM "chrome://gm-notifier/locale/gm-notifier.dtd">
  6. <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  7.         title="¬ifier.debugconsole.title;"
  8.         buttons="accept"
  9.         style="min-height: 200px; min-width: 450px;"
  10.         onload="loadLog()">
  11.  
  12.   <script type="application/x-javascript" src="chrome://gm-notifier/content/gm-prefs.js"/>
  13.   <script>
  14.     <![CDATA[
  15.       function loadLog() {
  16.         document.getElementById("logwindow").contentWindow.document.body.style.fontSize = "0.8em";
  17.         document.getElementById("logwindow").contentWindow.document.body.style.width = "98%";
  18.  
  19.                var service = Components.classes["@mozilla.org/GMailNotifier;1"]
  20.                                 .getService(Components.interfaces.nsIGMNotifierService);
  21.  
  22.         var str = service.getLog();
  23.         var list = str.split("|||");
  24.  
  25.         var logiframe = document.getElementById("logwindow").contentWindow.document.body;
  26.  
  27.         for (var run = 0; run < list.length-1; run++) {
  28.           var div = document.createElement("div");
  29.           div.style.border = "1px solid black";
  30.           div.style.padding = "5px";
  31.           div.style.marginBottom = "5px";
  32.           div.style.display = "block";
  33.  
  34.           if ((list[run][0] == " ") && (list[run][1] == " ")) {
  35.             div.style.marginLeft = "20px"
  36.           }
  37.  
  38.           div.textContent = list[run];
  39.           logiframe.appendChild(div);
  40.         }
  41.  
  42.         //var button = document.documentElement.getButton("extra2");
  43.         //button.addEventListener("command", clearConsole, false);
  44.         //button.setAttribute("icon", "clear");
  45.       }
  46.  
  47.       function clearConsole() {
  48.         var service = Components.classes["@mozilla.org/GMailNotifier;1"].getService().wrappedJSObject;
  49.  
  50.         service.clearLog();
  51.  
  52.         document.getElementById("logwindow").contentWindow.document.body.innerHTML = "";
  53.       }
  54.  
  55.       function createObserver() {
  56.         return ({
  57.           data : "",
  58.  
  59.           onStartRequest : function (aRequest, aContext) {
  60.             this.data = "";
  61.           },
  62.  
  63.           onDataAvailable : function (aRequest, aContext, aStream, aSourceOffset, aLength){
  64.             var scriptableInputStream = 
  65.               Components.classes["@mozilla.org/scriptableinputstream;1"]
  66.                         .createInstance(Components.interfaces.nsIScriptableInputStream);
  67.             scriptableInputStream.init(aStream);
  68.  
  69.             this.data += scriptableInputStream.read(aLength);
  70.           },
  71.  
  72.           onStopRequest : function (aRequest, aContext, aStatus) {
  73.             // XXX: proxy issue: aStatus is an error from http://lxr.mozilla.org/seamonkey/source/netwerk/base/public/nsNetError.h#172
  74.             finishSubmit(this.data);
  75.           },
  76.  
  77.           // nsIInterfaceRequestor
  78.           getInterface: function (aIID) {
  79.             try {
  80.               return this.QueryInterface(aIID);
  81.             } catch (e) {
  82.               throw Components.results.NS_NOINTERFACE;
  83.             }
  84.           },
  85.  
  86.           // nsIProgressEventSink (to shut up annoying debug exceptions
  87.           onProgress : function (aRequest, aContext, aProgress, aProgressMax) { },
  88.           onStatus : function (aRequest, aContext, aStatus, aStatusArg) { },
  89.  
  90.           // nsIHttpEventSink (to shut up annoying debug exceptions
  91.           onRedirect : function (aOldChannel, aNewChannel) { },
  92.  
  93.           QueryInterface : function(aIID) {
  94.             if (aIID.equals(nsISupports) ||
  95.                 aIID.equals(Components.interfaces.nsIDocShell) ||
  96.                 aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
  97.                 aIID.equals(Components.interfaces.nsIChannelEventSink) || 
  98.                 aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  99.                 aIID.equals(Components.interfaces.nsIProgressEventSink) ||
  100.                 aIID.equals(Components.interfaces.nsIPrompt) ||
  101.                 aIID.equals(Components.interfaces.nsIHttpEventSink) ||
  102.                 aIID.equals(Components.interfaces.nsIDocShellTreeItem) ||
  103.                 aIID.equals(Components.interfaces.nsIStreamListener))
  104.               return this;
  105.  
  106.             throw Components.results.NS_NOINTERFACE;
  107.           }
  108.         }
  109.         );
  110.       }
  111.  
  112.       function finishSubmit(aData) {
  113.         document.getElementById("submitButton").disabled = false;
  114.         document.getElementById("handleTextBox").value = aData;
  115.       }
  116.  
  117.       function sendLog() {
  118.         //Components.utils.import("resource://gre/modules/JSON.jsm");
  119.  
  120.         var service = Components.classes["@mozilla.org/GMailNotifier;1"].getService();
  121.  
  122.         var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  123.  
  124.         // create an nsIURI
  125.         var uri = ioService.newURI("http://nexgenmedia.net/extensions/gmnLogPost.php", null, null);
  126.  
  127.         //nsIInputStream
  128.         var uploadStream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream);
  129.  
  130.         var log = service.getLog();
  131.         var data = {"log": log, "description": document.getElementById("descriptionTextBox").value};
  132.         var postdata = "postdata="+encodeURIComponent(JSON.stringify(data));
  133.         uploadStream.setData(postdata, postdata.length);
  134.  
  135.         // get a channel for that nsIURI
  136.         var channel = ioService.newChannelFromURI(uri);
  137.  
  138.         // get a httpchannel and make it a post
  139.         var httpChannel = channel.QueryInterface(Components.interfaces.nsIHttpChannel);
  140.  
  141.         var uploadChannel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);
  142.         uploadChannel.setUploadStream(uploadStream, "application/x-www-form-urlencoded", -1);
  143.  
  144.         // order important - setUploadStream resets to get/put
  145.         httpChannel.requestMethod = "POST";
  146.  
  147.         var observer = createObserver();
  148.  
  149.         channel.notificationCallbacks = observer;
  150.  
  151.         // disable button
  152.         document.getElementById("submitButton").disabled = true;
  153.         channel.asyncOpen(observer, null);
  154.       }
  155.     ]]>
  156.   </script>
  157.  
  158.   <iframe id="logwindow" flex="0" src="" style="display:none"/>
  159.   <vbox>
  160.     <description>¬ifier.debugconsole.submitDescription;</description>
  161.     <description>¬ifier.debugconsole.privacyDescription;</description>
  162.  
  163.     <vbox style="margin-top: 20px;">
  164.       <label for="descriptionTextBox" value="¬ifier.debugconsole.handleDescriptionLabel;"/>
  165.       <textbox multiline="true" id="descriptionTextBox" value=""/>
  166.     </vbox>
  167.     <hbox align="center">
  168.       <button id="submitButton" label="¬ifier.debugconsole.submitButton.label;" accesskey="¬ifier.debugconsole.submitButton.accesskey;" oncommand="sendLog()"/>
  169.       <hbox flex="0" align="center">
  170.         <spacer flex="1"/>
  171.         <label value="¬ifier.debugconsole.handleLabel;"/>
  172.         <textbox id="handleTextBox" value=""/>
  173.       </hbox>
  174.     </hbox>
  175.   </vbox>
  176. </dialog>
  177.